#!/usr/bin/evn python
# -*- coding: UTF-8 -*-
# @File: contacts_page.py
# @Author: fy
# @date: 2021/9/6 12:02
from appium.webdriver.common.mobileby import MobileBy

from pages.add_member_page import AddMemberPage
from pages.base_page import BasePage
from pages.manage_contact_page import ManageContactsPage
import pytest


class ContactsPage(BasePage):
    _add_contact_btn_locator = (MobileBy.XPATH, '//*[@text="添加成员"]')
    _manage_contact_btn_locator = (MobileBy.XPATH, '//*[@class="android.widget.ListView"]/preceding-sibling::android.widget.RelativeLayout//*[@class="android.widget.TextView"]')

    def add_contact(self):
        '''
        企业微信添加联系人
        :return: AddMemberPage
        '''

        add_mem_ele = self.scroll_find_element(self._add_contact_btn_locator)
        if add_mem_ele:
            add_mem_ele.click()
        return AddMemberPage(self.driver)

    def goto_manage_contact_page(self):
        '''
        点击右上角 跳转到管理联系人
        :return:
        '''
        eles = self.find_elements(self._manage_contact_btn_locator)
        if eles and len(eles) > 0:
            eles[-1].click()


        return ManageContactsPage(self.driver)

        pass

    # def add_contacts(self):
    #     '''
    #     企业微信添加多条联系人
    #     :return:
    #     '''
    #     self.startApp()
    #
    #     pass
